/*用户名*/
var username = $("[name=username]");
/*密码*/
var password = $("[name=password]");
/*是否记住密码*/
var remember = false;
var isChecked;

/*layui初始化*/
layui.config({
    base: path + '/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['index', 'user'], function () {
    var $ = layui.$
        , admin = layui.admin
        , form = layui.form
    form.render();


    $("[lay-filter=LAY-user-login-submit]").bind("click", function () {
        var loadIcon = layer.load(0, {
            shade: true,
            time: false,
            shade: [0.1, '#fff']
        });
        if (username.val() == "") {
            username.focus();
            layer.msg('用户名不能为空!', {
                icon: 0,
                time: 2000
            });
            return false;
        } else if (password.val() == "") {
            password.focus();
            layer.msg('密码不能为空!', {
                icon: 0,
                time: 2000
            });
            return false;
        }
        isChecked = $(".layui-form-checked");
        if (isChecked.length == 1) {
            remember = true;
        }
        $.ajax({
            url: path + "/doLogin.json" //实际使用请改成服务端真实接口
            , type: "POST"
            , dataType: "JSON"
            , data: {
                "userName": username.val(), "userPassWord": password.val(), "remember": remember,
                "ip": ip, "address": address
            }
            , success: function (res) {
                layer.close(loadIcon);
                if (res.isSuccess == "0") {
                    layer.msg(res.msg, {
                        icon: 2,
                        time: 2000
                    });
                } else {
                    //登入成功的提示与跳转
                    layer.msg(res.msg, {
                        offset: '9px'
                        , icon: 1
                        , time: 1000
                    }, function () {
                        //后台主页
                        location.href = path + "/main/home.html";
                    });
                }
            }, error: function () {
                layer.msg("认证接口出现异常,请联系系统管理员！", {
                    icon: 2,
                    time: 2000
                });
                layer.close(loadIcon);
            }
        });
    })
});

